<?
set_time_limit(100);
require_once("../config/dbconn.php");

$curday=date('Y-m-d',$curtime);

$sqldy="select count(id) as c from {$db_prefix}users  where isfl=0 and confirmtime<={$curtime}";
$rsdy=$db->get_one($sqldy);

if (intval($rsdy['c'])>0){
echo intval($rsdy['c'])."个<Br>";
$sql="select id,username,tjnum,flprice from {$db_prefix}users where 1 order by id desc";
echo $sql."<Br>";
$result=$db->query($sql);
while($rs=$db->fetch_array($result)){
	$flprice=0;
	//获取比他大的会员，。还有几个没有返利
	$sqldy1="select count(id) as c from {$db_prefix}users where id>'".$rs['id']."' and isfl=0 and confirmtime<='$curtime'";
	$rsdy1=$db->get_one($sqldy1);
	$flprice=intval($rsdy1['c'])*$glo_fanliprice;	
if ($flprice>0){	
	////////////////////
	//今天已经获取了多少返利
	$sqljt="select sum(price) as c from {$db_prefix}caiwu where userid='".$rs['id']."' and from_unixtime(addtime,'%Y-%m-%d')='$curday' and ptype=3 and type=15";
	echo $sqljt."<Br>";
	$rsjt=$db->get_one($sqljt);
	$jtprice=floatval($rsjt['c']);
	
	//这个会员今天可以获取多少?
		$tjnum=intval($rs['tjnum']);
		if ($tjnum>7) $tjnum=7;
		$glornamre="glo_fanli_{$tjnum}";
		$flpricecan=$$glornamre;
		
		//是否已经超过了今天的返利
		if ($jtprice>=$flpricecan){
			$flprice=0;
		}else{
			if (($jtprice+$flprice)>$flpricecan){
				$flprice=$flpricecan-$jtprice;
			}
		}
	
	if ($flprice>0){
		$glornamfd="glo_fanlimax_{$tjnum}";
		$flpricefd=$$glornamfd;
		if ($rs['flprice']>=$flpricefd){
			$flprice=0;
		}else{
			if (($rs['flprice']+$flprice)>$flpricefd){
				$flprice=$flpricefd-$rs['flprice'];
			}
		}
	}
	
	////////////////////
	if ($flprice>0){
		$sqlj="update {$db_prefix}users set flprice=flprice+'$flprice',jjprice=jjprice+'$flprice' where username='".trim($rs['username'])."'";
		echo $sqlj."<Br>";
		$db->query($sqlj);
		//财务记录
		$e_userid=$rs['id'];$e_price=$flprice;$e_type=15;$e_ptype=3;$e_addtime=$curtime;$e_memo="{$username}注册";
		hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);		
	}
	//////////////////////
}
}
$db->free_result($result);
	$sqldy1="update {$db_prefix}users set isfl=1 where isfl=0 and confirmtime<={$curtime}";
	$db->query($sqldy1);
}

echo date('Y-m-d H:i:s',$curtime)."执行完毕<Br>";
?>